# -*- coding: utf-8 -*-
"""
错误测试API端点
用于测试各种HTTP错误状态码
"""

from fastapi import APIRouter, HTTPException, status

# 创建路由器
router = APIRouter()


@router.get("/400")
async def error_400():
    """
    测试400错误 - 请求参数错误
    
    Raises:
        HTTPException: 400错误
    """
    raise HTTPException(
        status_code=status.HTTP_400_BAD_REQUEST,
        detail="请求参数错误"
    )


@router.get("/401")
async def error_401():
    """
    测试401错误 - 未授权
    
    Raises:
        HTTPException: 401错误
    """
    raise HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail="未授权访问",
        headers={"WWW-Authenticate": "Bearer"}
    )


@router.get("/403")
async def error_403():
    """
    测试403错误 - 禁止访问
    
    Raises:
        HTTPException: 403错误
    """
    raise HTTPException(
        status_code=status.HTTP_403_FORBIDDEN,
        detail="禁止访问"
    )


@router.get("/404")
async def error_404():
    """
    测试404错误 - 资源不存在
    
    Raises:
        HTTPException: 404错误
    """
    raise HTTPException(
        status_code=status.HTTP_404_NOT_FOUND,
        detail="资源不存在"
    )


@router.get("/422")
async def error_422():
    """
    测试422错误 - 数据验证失败
    
    Raises:
        HTTPException: 422错误
    """
    raise HTTPException(
        status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
        detail="数据验证失败"
    )


@router.get("/500")
async def error_500():
    """
    测试500错误 - 服务器内部错误
    
    Raises:
        HTTPException: 500错误
    """
    raise HTTPException(
        status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
        detail="服务器内部错误"
    )


@router.get("/503")
async def error_503():
    """
    测试503错误 - 服务不可用
    
    Raises:
        HTTPException: 503错误
    """
    raise HTTPException(
        status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
        detail="服务暂时不可用"
    )